import 'package:flutter_massage/common_lib/index.dart';
import 'package:flutter_massage/pages/message/message_bean.dart';
import 'package:flutter_massage/pages/message/message_utils.dart';
import 'package:flutter_massage/sqlite/db_manager.dart';
import 'package:get/get.dart';

class MessageLogic extends GetxController {
  static const String keyListener = 'key_listener_refresh_message_page';

  List<ChatBean> list = [];

  @override
  void onReady() async {
    super.onReady();

    refreshPage();

    CommonObservable().addObserver(keyListener, call);
  }

  @override
  void onClose() {
    super.onClose();
    CommonObservable().removeObserver(keyListener, call);
  }

  void call(key, [value]) => refreshPage();

  void refreshPage() async {
    list = await DbManager.getChatList(userId: MessageUtils.userKey);
    update();
  }
}
